<?php

spl_autoload_register('autoload');

function autoload($class_name) {

  $class_path_array = array(
      /* Pastas do sistema */
      "./",
      "View/",
      "Controller/",
      "DAO/",
      "Model/",
      "RN/",
      /*PHPMailer*/
      "phpMailer/",
      
      /* Smarty */
      "Smarty/",
      "Smarty/libs/",
      "Smarty/libs/sysplugins/"
  );

  $sufixo = ".class.php";
  $sufixo_smarty = ".php";
  $encontrado = false;
  $qtd_path = count($class_path_array);
  $posicao = 0;

  spl_autoload_extensions(".class.php");
  
  while (!$encontrado && $posicao < $qtd_path) {

    if (file_exists($class_path_array[$posicao] . $class_name . spl_autoload_extensions())) {
      require_once $class_path_array[$posicao] . $class_name . spl_autoload_extensions();
      $encontrado = true;
      $_SESSION['class_name'] = $class_name;
    }
    
    $posicao++;
  }
}

?>